<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">


    <title>辖区添加页面</title>

    <link rel="stylesheet" href="../extra.css">
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="../../../plugins/font-awesome/css/font-awesome.min.css">
    <!-- IonIcons -->
    <link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../../dist/css/adminlte.min.css">
    <!-- Google Font: Source Sans Pro -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to to the body tag
to get the desired effect
|---------------------------------------------------------|
|LAYOUT OPTIONS | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body class="hold-transition sidebar-mini">
<div class="wrapper">
    <!-- Navbar -->
    <nav class="main-header navbar navbar-expand bg-white navbar-light border-bottom">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-widget="pushmenu" href="#"><i class="fa fa-bars"></i></a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="index.html" class="nav-link">主页</a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="#" class="nav-link">联系</a>
            </li>
        </ul>

        <!-- SEARCH FORM -->
        <form class="form-inline ml-3">
            <div class="input-group input-group-sm">
                <input class="form-control form-control-navbar" type="search" placeholder="搜索" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-navbar" type="submit">
                        <i class="fa fa-search"></i>
                    </button>
                </div>
            </div>
        </form>


        <!-- Right navbar links -->
        <ul class="navbar-nav ml-auto">
            <!-- Messages Dropdown Menu -->
            <!--<li class="nav-item dropdown">-->

            <li class="nav-item">
                <button style="font-weight: bold" type="button" class="button-pill button button-caution"
                        onclick="logout()">
                    退出
                </button>
            </li>

            <li class="nav-item">
                <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#"><i
                        class="fa fa-th-large"></i></a>
            </li>
        </ul>
    </nav>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
        <!-- Brand Logo -->
        <!--<a href="index3.html" class="brand-link">-->
        <!--<img src="dist/img/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"-->
        <!--style="opacity: .8">-->
        <!--<span class="brand-text font-weight-light">AdminLTE 3</span>-->
        <!--</a>-->

        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar user panel (optional) -->
            <div class="sidebar">
                <!-- Sidebar user (optional) -->
                <div class="user-panel mt-3 pb-3 mb-3 d-flex">
                    <div class="image">
                        <img src="../../../dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
                    </div>
                    <div class="info">
                        <a href="#" class="d-block">管理员</a>
                    </div>
                </div>

                <!-- Sidebar Menu -->
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
                        data-accordion="false">
                        <!-- Add icons to the links using the .nav-icon class
                             with font-awesome or any other icon font library -->
                        <li class="nav-item has-treeview">
                            <a href="index.html" class="nav-link">
                                <i class="nav-icon fa fa-dashboard"></i>
                                <p>
                                    概况
                                    <!--<i class="right fa fa-angle-left"></i>-->
                                </p>
                            </a>

                        </li>

                        <li class="nav-item has-treeview">
                            <a href="#" class="nav-link active">
                                <i class="nav-icon fa fa-table"></i>
                                <p>
                                    基础配置
                                    <i class="fa fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <!--<li class="nav-item">-->
                                <!--<a href="pages/tables/simple.html" class="nav-link">-->
                                <!--<i class="fa fa-circle-o nav-icon"></i>-->
                                <!--<p>Simple Tables</p>-->
                                <!--</a>-->
                                <!--</li>-->
                                <li class="nav-item">
                                    <a href="role.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>权限配置</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="user.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>用户信息</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="area.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>辖区配置</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="duty.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>职务配置</p>
                                    </a>
                                </li>
                            </ul>
                        </li>

                        <li class="nav-item has-treeview">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fa fa-table"></i>
                                <p>
                                    案件配置
                                    <i class="fa fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="casetype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>案件类型</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="objecttype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>使用对象类型</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="resourcetype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>使用资源</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="intended.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>使用目的</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="pictype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>图片类型</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="cardtype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>证件种类</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="idtype.html" class="nav-link">
                                        <i class="fa fa-circle-o nav-icon"></i>
                                        <p>目标类型</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </nav>
                <!-- /.sidebar-menu -->
            </div>
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0 text-dark">辖区添加</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item">主页</a></li>
                            <li class="breadcrumb-item active">辖区配置</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->

        </div>
        <!-- /.content-header -->

        <section class="content">
            <div class="row">

                <div class="col-2">
                </div>
                <div class="col-8">
                    <div class="card card-primary">
                        <div class="card-header">
                            <h3 class="card-title">辖区信息填写</h3>
                        </div>
                        <!-- /.card-header -->
                        <!-- form start -->
                        <!--data-inputmask="'alias': 'dd/mm/yyyy'" data-mask-->
                        <form role="form">
                            <div class="card-body">

                                <div class="form-group">
                                    <label for="g_name">辖区名 *</label>
                                    <input type="text" class="form-control" id="g_name"
                                           placeholder="辖区名">
                                </div>

                            </div>
                        </form>

                    </div>

                    <center>
                        <div class="button-group" style="margin:10px auto">
                            <button type="button" class="button button-pill button-lg button-action"
                                    onclick="addGoods()">提交
                            </button>
                            <button type="button" class="button button-pill button-lg button-primary" onclick="reset()">
                                重置
                            </button>
                            <button type="button" class="button button-pill button-lg button-caution"
                                    onclick="location='goinfo.html'">取消
                            </button>
                        </div>
                    </center>

                </div>
                <div class="col-2">
                </div>

            </div>
            <!--&lt;!&ndash; /.row &ndash;&gt;-->
        </section>

    </div>
    <!-- /.content -->
    <!-- /.content-wrapper -->

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->

    <!-- Main Footer -->
    <footer class="main-footer">
        <!-- To the right -->
        <div class="float-right d-none d-sm-block-down">
            Anything you want
        </div>
        <!-- Default to the left -->
        <strong>Copyright &copy; 2018 Solitary.</strong> All rights reserved.
    </footer>
</div>
<!-- ./wrapper -->

<!-- REQUIRED SCRIPTS -->

<!-- jQuery -->
<script src="../../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="../../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE -->
<script src="../../../dist/js/adminlte.js"></script>

<!-- OPTIONAL SCRIPTS -->
<script src="../../../plugins/chart.js/Chart.min.js"></script>
<script src="../../../dist/js/demo.js"></script>
<script src="../../../dist/js/pages/dashboard3.js"></script>
<script>

  var user_token = sessionStorage.getItem('user_token')


  $(function () {
    renderShopSelect()
  })

  function renderShopSelect() {
    var user_uuid = sessionStorage.getItem('user_uuid')

    var settings = {
      'async': true,
      'crossDomain': true,
      'url': 'http://127.0.0.1:5744/api/shopinfos/shop/' + user_uuid,
      'method': 'GET',
      'headers': {
        'Authorization': user_token
      }
    }


    $.ajax(settings)
      .done(function (response) {
        // response = JSON.parse(response)
        console.log(response)
        var html = ''
        if (response.code == 0) {
          for (var i = 0; i < response.data.length; ++i) {
            html += '<option>' + response.data[i].uuid + '</option>\n'
          }
          $('#s_i_uuid')
            .html(html)
        } else {
          alert(response.message)
        }
      })

  }

  function checknum(obj) {
    if (/^\d+\.?\d{0,2}$/.test(obj.value)) {
      obj.value = obj.value
    } else {
      obj.value = obj.value.substring(0, obj.value.length - 1)
    }
  }


  function uploadImg() {
    let form = new FormData()
    form.append('image', $('#mypic')[0].files[0])

    let settings = {
      'async': true,
      'crossDomain': true,
      'url': 'http://127.0.0.1:5744/api/images/upload',
      'method': 'PUT',
      'headers': {
        'Authorization': user_token
      },
      'processData': false,
      'contentType': false,
      'mimeType': 'multipart/form-data',
      'data': form
    }

    $.ajax(settings)
      .done(function (response) {
        console.log(response)
        response = JSON.parse(response)
        if (response.code == 0) {
          $('#img_uri')
            .attr('href', response.data)
          $('#img_uri')
            .text(response.data)
          $('#g_img')
            .val(response.data)
          $('#g_simg')
            .val(response.data)
        } else {
          alert('图片上传失败!')
        }
      })

  }

  function addGoods() {
    let s_i_uuid = $('#s_i_uuid')
      .find('option:selected')
      .text()
    let g_name = $('#g_name')
      .val()
    let g_price = $('#g_price')
      .val()
    let g_quantity = $('#g_quantity')
      .val()
    let g_ly = $('#g_ly')
      .val()
    let g_vid = $('#g_vid')
      .val()
    let g_img = $('#g_img')
      .val()
    let g_simg = $('#g_simg')
      .val()
    let g_label = $('#g_label')
      .val()
    let g_detail = $('#g_detail')
      .val()


    if (isnull(s_i_uuid) || isnull(g_name) || isnull(g_price) || isnull(g_quantity) || isnull(g_ly) || isnull(g_vid)) {
      alert('请填写带 * 的必填信息')
    } else if (parseInt(g_quantity) <= 0) {
      alert('商品数量必须大于 0')
    } else {
      let form = new FormData()
      form.append('s_i_uuid', s_i_uuid)
      form.append('g_name', g_name)
      form.append('g_price', g_price)
      form.append('g_quantity', g_quantity)
      form.append('g_ly', g_ly)
      form.append('g_vid', g_vid)
      if (!isnull(g_img)) {
        form.append('g_img', g_img)
      }
      if (!isnull(g_simg)) {
        form.append('g_simg', g_simg)
      }
      if (!isnull(g_label)) {
        form.append('g_label', g_label)
      }
      if (!isnull(g_detail)) {
        form.append('g_details', g_detail)
      }


      const settings = {
        'async': true,
        'crossDomain': true,
        'url': 'http://127.0.0.1:5744/api/goods',
        'method': 'POST',
        'headers': {
          'Authorization': user_token
        },
        'processData': false,
        'contentType': false,
        'mimeType': 'multipart/form-data',
        'data': form
      }

      $.ajax(settings)
        .done(function (response) {
          response = JSON.parse(response)
          if (response.code == 0) {
            alert(response.message)
            // $('#login-form').attr('action', '../admin/index.html')
            window.location.href = 'goinfo.html'

          } else {
            alert(response.message)
          }
        })

    }


  }

  function reset() {
    $('#s_i_uuid')
      .val('')
    $('#g_name')
      .val('')
    $('#g_price')
      .val('')
    $('#g_quantity')
      .val('')
    $('#g_ly')
      .val('')
    $('#g_vid')
      .val('')
    $('#g_img')
      .val('')
    $('#g_simg')
      .val('')
    $('#g_label')
      .val('')
    $('#g_detail')
      .val('')

  }


  function isnull(val) {
    var str = val.replace(/(^\s*)|(\s*$)/g, '')//去除空格;

    if (str == '' || str == undefined || str == null) {
      //return true;
      console.log('空')
    } else {
      //return false;
      console.log('非空')
    }
  }

  function logout() {
    sessionStorage.removeItem('user_token')
    window.location.href = '../common/login.html'

  }


</script>
</body>
</html>
